package com.example.park2301.message

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.example.lib_base.entity.MessageBeanItem
import com.example.park2301.R
import com.example.park2301.databinding.ItemMessageBinding

class MessageAdapter:PagingDataAdapter<MessageBeanItem, MessageAdapter.MessageViewHolder>(holl) {

    companion object{
        val  holl =object :ItemCallback<MessageBeanItem>(){
            override fun areItemsTheSame(
                oldItem: MessageBeanItem,
                newItem: MessageBeanItem
            ): Boolean {
                return oldItem==newItem
            }

            override fun areContentsTheSame(
                oldItem: MessageBeanItem,
                newItem: MessageBeanItem
            ): Boolean {
                return oldItem.id==newItem.id
            }

        }
    }
    class MessageViewHolder(view:View):ViewHolder(view){
        val binding =DataBindingUtil.bind<ItemMessageBinding>(view)
    }

    override fun onBindViewHolder(holder: MessageViewHolder, position: Int) {
        holder.binding?.bean =getItem(position)
        if (getItem(position)?.messageStatus=="处理中"){
            holder.binding?.tvSs?.setBackgroundResource(R.drawable.bg_chuli)
        }else if (getItem(position)?.messageStatus=="已过期"){
            holder.binding?.tvSs?.setBackgroundResource(R.drawable.bg_guoqi)
        }else if (getItem(position)?.messageStatus=="已读"){
            holder.binding?.tvSs?.setBackgroundResource(R.drawable.bg_yidu)
        }
//        if (getItem(position)?.messageType=="车位管理"){
//            holder.binding?.iv?.setImageResource(R.drawable.ic_car)
//        }else if (getItem(position)?.messageType=="系统通知"){
//            holder.binding?.iv?.setImageResource(R.drawable.ic_laba)
//        }else if (getItem(position)?.messageType=="物业服务"){
//            holder.binding?.iv?.setImageResource(R.drawable.ic_build)
//        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_message, parent, false)
        return MessageViewHolder(view)
    }
}